public class test11 {
    public int minSubArrayLen(int target, int[] nums) {
        //滑动窗口
        int left = 0,right = 0;
        int sum = 0;
        int res = Integer.MAX_VALUE;
        while(left<=right && right<nums.length){
            sum += nums[right];
            while(sum>=target){
                //更新窗口
                //更新前先记录
                res = Math.min(res,right-left+1);
                sum -= nums[left++];
                //left++;
            }
            right++;
        }
        return res==Integer.MAX_VALUE?0:res;
    }
}
